
public class Task2 {

	
	public static void main(String[] args) {
		
		int n = 4;
		int[][] arr = new int[4][4];
		boolean moveUp = false;
		boolean moveDown = true;
		int row = 0;
		int col = 0;
		int counter = 1;
		
		while(counter <=16){
		if(moveDown){
			if(col-1>=0 && row+1<arr.length){
				arr[row+1][col-1]=counter;
				counter++;
				col=-1;
				row+=1;
			}else{
				if(row+1<arr.length){
				arr[row][col]= counter;
				counter++;
				row+=1;
				arr[row][col]= counter;
				counter++;
				moveDown=false;
				moveUp=true;
				}
			}
		}
		if(moveUp){
			if(row-1>=0 && col+1 <arr[0].length){
				arr[row-1][col+1]=counter;
				counter++;
				row--;
				col++;
		
			}else{
				if(col+1<arr[0].length){
					arr[row][col]= counter;
					counter++;
					col++;
					arr[row][col]= counter;
					counter++;
					moveUp=false;
					moveDown=true;
					
				}
			}}
			
		}
		
		
		for (int i = 0; i < arr.length; i++) {
			System.out.println();
			for (int j = 0; j < arr[0].length; j++) {
				System.out.print(arr[i][j]+" ");
			}
		

	}
	}
}

